//
//  KeychainHandler.swift
//  TestWorkSpace
//
//  Created by Mac on 2020/1/8.
//  Copyright © 2020 jhf. All rights reserved.
//

import Foundation
import KeychainAccess
import CooperSwift

enum KeychainEnum {
    case udid
}

class KeychainHandler {
    
    static let shared = KeychainHandler()
    
    lazy var keychain: Keychain = {
        let keychain = Keychain(service: BundleInfo.identifier)
        return keychain
    }()
    
    func save(key: String, value: String) {
        keychain[key] = value
    }
    
    func items() -> [[String: Any]] {
        return keychain.allItems()
    }
    
    func remove(key: String) -> Bool {
        if try! keychain.contains(key) {
            return ((try? keychain.remove(key)) != nil)
        }
        return false
    }
    
    func removeAll() -> Bool {
        return ((try? keychain.removeAll()) != nil)
    }
    
}
